/*
 * Created by SharpDevelop.
 * User: MyWife
 * Date: 6/19/2009
 * Time: 10:47 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using popLib;
using System.IO;

namespace SlideShowGadget
{
	/// <summary>
	/// Description of Options.
	/// </summary>
	public partial class Options : SidebarGadgetOption
	//public partial class Options : Form
	{
		public Options(SidebarGadget sidebarGadget):base(sidebarGadget)
		{
			InitializeComponent();
			
			txt_src.Text    = sidebarGadget.Options[ Start.optionsType.StartupDirectory+"" ]+"";
			cbx_wallstyle.Items.AddRange( "Centered,Stretched,Tiled,Auto Scaled,Full Scaled".Split(',') );
			
			try{
				int seconds = NumberLib.getInt( sidebarGadget.Options[ Start.optionsType.DelayTimer+"" ]+"" );
				if( seconds%3600 == 0 ){
					seconds = seconds/3600;
					cbx_time.SelectedIndex = 2;
				}else if( seconds%60 == 0 ){
					seconds = seconds/60;
					cbx_time.SelectedIndex = 1;
				}else cbx_time.SelectedIndex = 0;
				nud_delay.Value = seconds;
			}catch{ this.nud_delay.Value = nud_delay.Minimum; }
			
			cbx_apply.Checked = sidebarGadget.Options[ Start.optionsType.SetAsWallpager+"" ]+"" == "1" ? true : false;
			
			switch( sidebarGadget.Options[Start.optionsType.WallpaperStyle+""].ToString().ToLower() ){
				case "centered": cbx_wallstyle.SelectedIndex = 0; break;
				case "stretched": cbx_wallstyle.SelectedIndex = 1; break;				
				case "tiled": cbx_wallstyle.SelectedIndex = 2; break;								
				case "autoscaled": cbx_wallstyle.SelectedIndex = 3; break;
				default:
				case "fullscaled": cbx_wallstyle.SelectedIndex = 3; break;
			}
			
		}
		
		//public Options(){}
		
		void ActionEvent(object sender, EventArgs e)
		{
			switch( ((Control)sender).Name ){
				case "btn_ok":
					if( !Directory.Exists( txt_src.Text ) && !FormLib.confirm("Image source directory is not existed. Do you want to continue?") ) return;
					Hashtable options = sidebarGadget.Options;
					options[Start.optionsType.StartupDirectory+""] 	= txt_src.Text;
					options[Start.optionsType.DelayTimer+""] 		= nud_delay.Value * ( cbx_time.SelectedIndex == 0 ? 1 : cbx_time.SelectedIndex == 1 ? 60 : 3600 );
					options[Start.optionsType.SetAsWallpager+""]    = cbx_apply.Checked ? 1 : 0;
					options[Start.optionsType.WallpaperStyle+""]    = cbx_wallstyle.SelectedItem.ToString().Replace(" ","");
					sidebarGadget.Options = options;
					this.Hide();
					break;
				case "btn_cancel": this.Hide(); break;
				case "btn_browse":
					ReturnSet rs = FormLib.folderBrowser();
					if( rs.Success ) txt_src.Text = rs.Result.ToString();
				break;
			}
		}
	}
}
